package com.hutao.manage.comparator;

import java.util.Comparator;
import java.util.regex.Pattern;

import com.hutao.manage.pojo.cust.MedicalRecordPrinterImage;

public class MedicalRecordPrinterImageComparator implements Comparator<MedicalRecordPrinterImage> {

	@Override
	public int compare(MedicalRecordPrinterImage o1, MedicalRecordPrinterImage o2) {
		//首先根据打印类型排序,小的在前大的在后
		if(!o1.getPrinterTypeId().equals(o2.getPrinterTypeId())){
			return o1.getPrinterTypeId().compareTo(o2.getPrinterTypeId());
		}else{
			//根据图片的原文件名排序, 小的在前, 大的在后
			if(o1.getOriginalName()!=null && o2.getOriginalName()!=null){
				if(isNumber(o1.getOriginalName()) && isNumber(o2.getOriginalName())){
					return o1.getOriginalName().compareTo(o2.getOriginalName());
				}
			}
			
			if (o1.getCreateDate() != null && o2.getCreateDate() != null) {
				return o1.getCreateDate().compareTo(o2.getCreateDate());
			}
		}
		return 0;
	}

	private boolean isNumber(String str){
		Pattern pattern = Pattern.compile("[0-9]*");
		return pattern.matcher(str).matches();
	}
}
